

<!-- 商品评价-列表 -->
<template>
	<view class="content">
		
		<!-- header部分 -->
		<view class='header-Container header-height'>
			<view class="header-bg"></view>
			<navHeader pageTitle="商品评价" rightBtnType="msgCenter" colorTheme="black" @toggleMenuListHandler="toggleMenuListHandler">
			</navHeader>
		</view>

		<view class="counts flex-center headerNext">
			<view :class="star ? 'flex-all-center' : 'flex-all-center sel'" @click="changeStar()">
				全部<text>{{ count.allCount }}</text>
			</view>
			<view :class="star != '10' ? 'flex-all-center' : 'flex-all-center sel'" @click="changeStar('10')">
				好评<text>{{ count.wellCount }}</text>
			</view>
			<view :class="star != '20' ? 'flex-all-center' : 'flex-all-center sel'" @click="changeStar('20')">
				中评<text>{{ count.midCount }}</text>
			</view>
			<view :class="star != '30' ? 'flex-all-center' : 'flex-all-center sel'" @click="changeStar('30')">
				差评<text>{{ count.badCount }}</text>
			</view>
		</view>
		

		<!-- 评价区域 -->
		<view v-if="list && list.length" class="judgeArea-Container">
			<view class="judgeList-Container">
				<view v-for="(item, index2) in list" :key="index2" class="judge-item">
					<view class="userInfo">
						<image class="profilePhoto" :src="imgSite + item.createUav"></image>
						<view class="nameStar">
							<view class="userName ellipsis1">{{ item.createUnm }}</view>
							<view class="star-Container">
								<image v-for="(item, index) in parseInt(item.star)" :key="index" class="starIcon" :src="icon.starColor" mode=""></image>
								<image v-for="(item, index) in 5 - parseInt(item.star)" :key="'--' + index" class="starIcon" :src="icon.starDefault"mode=""></image>
								
								<view class="judge-time">
									{{item.createDt | timestampToTime}}
								</view>
							</view>
						</view>
					</view>
					<view class="judgeContent">{{ item.content }}</view>
					<view class="judgeImages" v-if="item.img[0]!=imgSite">
						<image v-for="(img, index) in item.img" :key="index" :src="img" mode="" @click="checkPic(img,index2)"></image>
						<image v-if="item.img.length%4 != 0" v-for="(item2, index2) in 4-item.img.length%4" :key="'a'+index2" style="visibility: hidden;"></image>
					</view>
					<view class="judgeSpec ellipsis1">
						{{item.goodsCategoryAttr | getSpecStr}}
					</view>
					
					<!-- 店家回复 -->
					<image v-if="item.replyContent" class="splitLinebar" :src="icon.splitLinebar" mode=""></image>
					<view v-if="item.replyContent" class="shopReplay">
						{{item.replyContent}}
					</view>
				</view>
			</view>
		</view>
		<g-empty v-else></g-empty>
		
		
		<!-- 详情菜单 -->
		<view v-if="showDetailMenu" @click="toggleMenuListHandler()" class="detailMenu-Container">
			<detailMenu></detailMenu>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	
	import navHeader from '@/components/nav-header/nav-header';
	import detailMenu from "@/components/detailMenu/detailMenu";
	
	export default {
		components: {
			navHeader,
			detailMenu
		},
		filters: {

			//已选规格Str 
			getSpecStr(json) {
				console.log(json);

				var str = "";
				json = JSON.parse(json);
				console.log(json);
				for (var i = 0; i < json.length; i++) {
					str += ('"' + json[i]["value"] + '" ');
				}
				return str;
			},
			
			
			// 时间戳转换日期--补0--毫秒
			timestampToTime(timestamp) {
				var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var Y = date.getFullYear() + '.';
				var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '.';
				var D = date.getDate() < 10 ?  '0'+date.getDate()+ ' ' : date.getDate()+ ' ';
				var h = date.getHours() < 10 ? '0'+date.getHours()+ ':' : date.getHours()+ ':';
				var m = date.getMinutes() < 10 ? '0'+date.getMinutes()+ ':' : date.getMinutes()+ ':';
				var s = date.getSeconds()< 10 ? '0'+date.getSeconds() : date.getSeconds();
				return Y+M+D+h+m+s;
			}
		},
		data() {
			return {
				icon: {
					starColor: "/static/images/detail/star_color.png",
					starDefault: "/static/images/detail/star_default.png",
					splitLinebar: "/static/images/detail/splitLinebar.png"
				},
				
				//详情菜单
				showDetailMenu: false,
				
				id: '',
				list: [],
				count: {},
				star: null,
				top: '0px',
				
				//分页相关
				pageNum: 1,
				pageSize: 10
			};
		},
		computed: {
			...mapState(['hasLogin', 'imgSite'])
		},
		onLoad(option) {
			this.id = option.id;
			this.getCount();
			this.getData();
			let that = this;
			uni.getSystemInfo({
				success(res) {
					that.top = res.windowTop + 'px';
				}
			});
		},
		methods: {
			
			//详情菜单
			toggleMenuListHandler() {
				console.log("afsdf ");
				this.showDetailMenu = !this.showDetailMenu;
			},
			
			checkPic(pic,index){
				let that = this; 
				uni.previewImage({
					current:pic,
					urls: that.list[index].img,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			//评论数据
			getData() {
				let that = this;
				that.$api.globalUtil.requestAjax({
					url: '/GoodsApi/findGoodsEvaluateListForApi',
					method: 'POST',
					data: {
						goodsCd: that.id,
						star: that.star,
						pageNum: that.pageNum,
						pageSize: that.pageSize
					},
					success: function(res) {
						
						that.total = res.data.response.total;
						
						if(res.data.response.results && res.data.response.results.length) {
							
							for(let i of res.data.response.results){
							   var a = i.img
							   a = a.split(',');
							   var b = [];
							   for(let i of a){
							   	b.push(that.imgSite + i);
							   }
							   i.img = b;
							}
							if(that.pageNum == 1) {
								that.list = res.data.response.results;
							}else {
								that.list = that.list.concat(res.data.response.results);
							}
						}else {
							that.$api.msg("没有更多评论了!");
						}
					}
				});
			},
			getCount() {
				let that = this;
				that.$api.globalUtil.requestAjax({
					url: '/GoodsApi/findGoodsEvaluateCountForApi',
					method: 'POST',
					data: {
						goodsCd: that.id
					},
					success: function(res) {
						that.count = res.data.response;
					}
				});
			},
			changeStar(star) {
				if (star) {
					this.star = star;
				} else {
					this.star = null;
				}
				this.pageNum = 1;
				this.list = [];
				this.getData();
			}
		},
		onPullDownRefresh() {
			var that = this;
			that.pageNum = 1;
			
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1500);
			
			that.getData();
		},
		onReachBottom() {
			var that = this;
			that.pageNum = that.pageNum + 1;
			
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1500);
			
			that.getData();
		}
	};
</script>

<style lang="less">
	page,
	.content {
		background: #f5f5f5;
		height: 100%;
	}
	
	
	/* header部分 */
	.header-Container {
		z-index: 999;
		position: fixed;
		top: 0;
		width: 100%;
		height: 176rpx;
		overflow: hidden;
		box-shadow: 0px 1rpx 1rpx 0px rgba(0, 0, 0, 0.08);
		background: rgba(255, 255, 255, 1);
	
		.leftBtns {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
	
			.back {
				margin-left: 17rpx;
				width: 44rpx;
				height: 44rpx;
			}
		}
	
		.title {
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
		}
	}
	

	// 数量
	.counts {
		padding: 0 30rpx;
		width: 100%;
		height: 124rpx;
		justify-content: space-around;
		background-color: white;
		position: fixed;
		top: 176rpx;
		left: 0;
		z-index: 10;

		view {
			width: 154rpx;
			height: 50rpx;
			color: #666666;
			font-size: 24rpx;
			background-color: #f5f5f5;
			border-radius: 25rpx;
		}

		.sel {
			// width: 152rpx;
			padding: 0 25rpx;
			height: 48rpx;
			color: #666666;
			font-size: 24rpx;
			background-color: #fff4f4;
			border-radius: 25rpx;
			border: 1rpx solid #FE5E49;
			color: #FE5E49;
		}

		text {
			font-weight: bold;
		}
	}

	/* 评价区域 */
	.judgeArea-Container {
		position: sticky;
		border-radius: 10rpx;
		
		/* #ifndef APP-PLUS */
		padding-top: 212rpx !important;
		/* #endif */
		/* #ifdef APP-PLUS */
		padding-top: calc(var(--status-bar-height) + 212rpx) !important;
		/* #endif */

		.header-Container {
			display: inline-block;
			position: relative;
			width: 100%;
			height: 26rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			color: rgba(51, 51, 51, 1);

			.judgeText {
				font-weight: bold;
				font-size: 28rpx;
			}

			.judgeCount {
				margin-left: 10rpx;
				font-weight: bold;
				font-size: 22rpx;
			}

			.all-Container {
				position: absolute;
				top: 0;
				right: 0px;
				width: 100rpx;
				text-align: right;

				.text {
					font-size: 24rpx;
					font-family: PingFang SC;
					color: rgba(102, 102, 102, 1);
					line-height: 29rpx;
				}

				image {
					margin-left: 15rpx;
					width: 11rpx;
					height: 19rpx;
				}
			}
		}

		.judgeList-Container {
			.judge-item {
				position: relative;
				margin-top: 20rpx;
				background-color: #ffffff;
				padding: 36rpx 30rpx 36rpx 30rpx;
				border-radius: 16rpx;

				&.borderOneRpx:after {
					border-top: 0;
					border-left: 0;
					border-right: 0;
					border-color: #eeeeee;
				}

				.userInfo {
					display: flex;
					width: 100%;
					height: 70rpx;

					.profilePhoto {
						width: 70rpx;
						height: 70rpx;
						border-radius: 50%;
					}

					.nameStar {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						margin-left: 24rpx;
						padding: 5rpx 0 10rpx 0;
						max-width: 575rpx;

						.userName {
							max-width: 590rpx;
							font-size: 24rpx;
							font-family: PingFang SC;
							// font-weight:500;
							color: rgba(51, 51, 51, 1);
						}

						.star-Container {
							display: flex;
							align-items: center;
							width: 590rpx;
							height: 20rpx;

							.starIcon {
								margin-right: 8rpx;
								width: 22rpx;
								height: 20rpx;
							}
							
							.judge-time {
								margin-left: auto;
								font-size:22rpx;
								font-family:PingFang SC;
								// font-weight:500;
								color:rgba(153,153,153,1);
							}
						}
					}
				}

				.judgeContent {
					margin-top: 20rpx;
					line-height: 31rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					// font-weight:500;
					color: rgba(51, 51, 51, 1);
				}

				.judgeImages {
					justify-content: space-between;
					display: flex;
					flex-wrap: wrap;
					margin-top: 28rpx;

					image {
						margin-bottom: 18rpx;
						width: 150rpx;
						height: 150rpx;
						border-radius: 10rpx;
					}
				}

				.judgeSpec {
					// margin-top: 25rpx;
					max-width: 100%;
					line-height: 31rpx;
					font-size: 20rpx;
					font-family: PingFang SC;
					// font-weight:500;
					color: rgba(153, 153, 153, 1);
				}
			}
		}

		//店铺回复
		.splitLinebar {
			margin: 0 auto;
			width: 690rpx;
			height: 11rpx;
		}
		.shopReplay {
			position: relative;
			padding: 27rpx 0 0 0;
			font-size: 22rpx;
			font-family: PingFang SC;
			// font-weight:500;
			color: rgba(153, 153, 153, 1);
			line-height: 31rpx;

			&.borderOneRpx::after {
				border-bottom: 0;
				border-left: 0;
				border-right: 0;
				border-color: #EEEEEE;
			}
		}
	}
</style>
